wayland: Throttle system bell requests
authorJonas Ådahl <jadahl@gmail.com>
Mon, 13 Mar 2017 06:42:38 +0000 (14:42 +0800)
committerJonas Ådahl <jadahl@gmail.com>
Thu, 20 Jul 2017 01:58:10 +0000 (09:58 +0800)
If a bad behaving application tries to make the window/display beep too
often, throttle the beep requests so that we don't end up filling the
Wayland socket queue.

The throttle is set to 50 beeps per second, which far more beeps than
will ever make any sense from a user experience point of view, but will
avoid terminating due to an excessive amount of requests.

https://bugzilla.gnome.org/show_bug.cgi?id=778188

gdk/wayland/gdkdisplay-wayland.c
gdk/wayland/gdkdisplay-wayland.h

index 0cca86ca7c85424a99d494b071a8d2f5ac558416..0baa2de21c6322f74b429e8ef9c37aabd19c8107 100644 (file)
@@ -83,6 +83,8 @@
  * ]|
  */
 
+#define MIN_SYSTEM_BELL_DELAY_MS 20
+
 static void _gdk_wayland_display_load_cursor_theme (GdkWaylandDisplay *display_wayland);
 
 G_DEFINE_TYPE (GdkWaylandDisplay, gdk_wayland_display, GDK_TYPE_DISPLAY)
@@ -666,6 +668,7 @@ gdk_wayland_display_system_bell (GdkDisplay *display,
 {
   GdkWaylandDisplay *display_wayland;
   struct gtk_surface1 *gtk_surface;
+  gint64 now_ms;
 
   g_return_if_fail (GDK_IS_DISPLAY (display));
 
@@ -679,6 +682,12 @@ gdk_wayland_display_system_bell (GdkDisplay *display,
   else
     gtk_surface = NULL;
 
+  now_ms = g_get_monotonic_time () / 1000;
+  if (now_ms - display_wayland->last_bell_time_ms < MIN_SYSTEM_BELL_DELAY_MS)
+    return;
+
+  display_wayland->last_bell_time_ms = now_ms;
+
   gtk_shell1_system_bell (display_wayland->gtk_shell, gtk_surface);
 }
 
index a68940f5b8d17dde128e44bb8bea9996adbfa1a6..1270405e11fef642e854c69520a50c277845c4b4 100644 (file)
@@ -110,6 +110,8 @@ struct _GdkWaylandDisplay
 
   GPtrArray *monitors;
 
+  gint64 last_bell_time_ms;
+
   /* egl info */
   EGLDisplay egl_display;
   int egl_major_version;